module WindSpirit
{
    export class Net
    {
        static EVENT_UPLOAD_SCORE_SUCCESS = "EVENT_UPLOAD_SCORE_SUCCESS";
        static EVENT_GET_RANK_SUCCESS = "EVENT_GET_RANK_SUCCESS";
        static upload_score_url = "http://www.windspirit.cn/upload/record.php?";
        static get_rank_url = "http://www.windspirit.cn/upload/rankListGet.php?";
        static get_shareinfo_url = "http://www.windspirit.cn/upload/shareNumberGet.php?";
        static get_my_rank_url = "http://www.windspirit.cn/upload/myRankGet.php?";
        static get_record_url = "http://www.windspirit.cn/upload/myRecordGet.php?";
        static uploadScore(score: number,cb: Function = null,thisObj = null)
        {
            var url = this.upload_score_url + WindSpirit.params + "&record=" + score;
            if(cb)
            {
                this.httpGet(url,cb,thisObj);
            }
            else
            {
                this.httpGet(url,this.httpGetComplete,this);
            }
        }
        static httpGet(url:string,cb:Function,thisObj)
        {
            var loader = new egret.URLLoader;
            var req = new egret.URLRequest;
            req.url = url;
            if(WindSpirit.Config.DEBUG)
            {
                console.log(url);
            }
            req.method = egret.URLRequestMethod.GET;
            loader.load(req);
            loader.addEventListener(egret.Event.COMPLETE,cb,thisObj);
        }
        static getMyRank(cb: Function,thisObj)
        {
            var url = this.get_my_rank_url + WindSpirit.params;
            this.httpGet(url,cb,thisObj);
        }
        static httpGetComplete(a)
        {
            if(WindSpirit.Config.DEBUG)
            {
                console.log(a.target.data);
            }
        }
        static getRankList(cb: Function,thisObj,count: number = 5)
        {
            var url = this.get_rank_url + WindSpirit.params + "&number=" + count;
            this.httpGet(url,cb,thisObj);
        }
        static getShareNumber(cb:Function,thisObj)
        {
            var url = this.get_shareinfo_url + WindSpirit.params;
            this.httpGet(url,cb,thisObj);
        }
        static getRecord(cb,thisObj)
        {
            var url = this.get_record_url + WindSpirit.params;
            this.httpGet(url,cb,thisObj);
        }
    }
}